package com.bbex.service.impl;/**
 * Created by Administrator on 2018/7/5.
 */

import com.bbex.entity.SysPara;
import com.bbex.mapper.SysParaDao;
import com.bbex.service.AppVersionService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * Title :
 * Description :
 * Create on : 2018年07月05
 * Copyright (C) zw.FinTec
 *
 * @author department:研发部
 *         username:TAOFEI
 * @version 修改历史:
 *          修改人 修改日期 修改描述
 *          -------------------------------------------<
 */
@Service
public class AppVersionServiceImpl implements AppVersionService {
    @Resource
    private SysParaDao sysParaMapper;

    /**
     * 获取App版本
     *
     * @param companyCode
     * @return
     */
    @Override
    public Map getVersion(String companyCode) {
        Map returnMap = new HashMap();
        SysPara  versionStatus = sysParaMapper.selectByPrimaryKey("version_status",companyCode);//版本更新状态（0：小版本 1：大版本）
        SysPara sysParam = sysParaMapper.selectByPrimaryKey("version",companyCode);//版本号
        SysPara sysPara = sysParaMapper.selectByPrimaryKey("app_url",companyCode);//小版本更新路径
        SysPara sysPara2 = sysParaMapper.selectByPrimaryKey("app_version_desc",companyCode);//app版本说明
        SysPara  androidSysParam = sysParaMapper.selectByPrimaryKey("androidUrl",companyCode);//安卓下载地址
        SysPara   iosSysParam = sysParaMapper.selectByPrimaryKey("iosUrl",companyCode);//ios下载地址
        if (sysParam==null || versionStatus==null){
            returnMap.put("flag",false);
            returnMap.put("msg","版本号获取失败!");
            return returnMap;
        }
        returnMap.put("flag", true);
        returnMap.put("msg", "版本号获取成功!");
        returnMap.put("versionName",sysParam.getParaValue());//版本号
        returnMap.put("versionStatus",versionStatus.getParaValue());//版本更新状态
        returnMap.put("androidLinkURL",androidSysParam.getParaValue());//android推广链接
        returnMap.put("iosLinkURL",iosSysParam.getParaValue());//ios推广链接
        returnMap.put("appUrl",sysPara.getParaValue());//小版本更新路径
        returnMap.put("newDescribe",sysPara2.getParaValue());//app版本说明
        return returnMap;
    }

    @Override
    public Map getLink(String companyCode) {
        Map returnMap = new HashMap();
        SysPara  androidSysParam = sysParaMapper.selectByPrimaryKey("androidUrl",companyCode);//安卓下载地址
        SysPara   iosSysParam = sysParaMapper.selectByPrimaryKey("iosUrl",companyCode);//ios下载地址
        if (androidSysParam==null || iosSysParam==null ){
            returnMap.put("flag",false);
            returnMap.put("msg","推广链接获取失败!");
            return returnMap;
        }
        returnMap.put("flag", true);
        returnMap.put("msg", "推广链接获取成功!");
        returnMap.put("androidLinkURL",androidSysParam.getParaValue());//android推广链接
        returnMap.put("iosLinkURL",iosSysParam.getParaValue());//ios推广链接
        return returnMap;
    }
}
